public class Solution {
    public boolean detectCapitalUse(String word) {
        int cnt = 0;
        for (char c : word.toCharArray()) {
            if (Character.isUpperCase(c)) {
                cnt++;
            }
        }
        return cnt == 0 || cnt == word.length() || cnt == 1 && Character.isUpperCase(word.charAt(0));
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        String word = "FlaG";
        System.out.println(solution.detectCapitalUse(word));
    }
}
